<?php
/**
 * file favorite.php
 * Created on 2015-4-3 下午2:45:55 
 * Create by xiweijie
 */
namespace haibao\www\business;

use \haibao\www\data\Favorite as FavoriteData;
class Favorite extends \haibao\www\business\Base{
    
    public static function getUseriMark($filter){
        $favoriteData = new FavoriteData();
        return $favoriteData->getAll($filter);
    }
    
    public static function saveiMark($model){
        if(empty($model->Aid)){
            throw new BusinessException('文章ID不能为空！');
        }
        if(empty($model->Title)){
            throw new BusinessException('标题不能为空！');
        }
        if(empty($model->IdType)){
            throw new BusinessException('收藏的类别不能为空！');
        }
        $model->Description = '';
        $model->SpaceUid = 0;
        $model->DateLine = time();
        $favoriteData = new FavoriteData();
        //收藏增加积分
        \haibao\user\common\ScoreRule::operateScore($model->Uid,\haibao\user\common\ScoreRule::TYPE_MARK);
        
        $favoriteData->add($model);
    }
    
    public static function deleteiMarkById($id){
        if(empty($id)){
            throw new BusinessException('Id不能为空！');
        }
        $favoriteData = new FavoriteData();
        $favoriteData->removeById($id);
    }
    
    public static function deleteiMarkByAidAndType($id,$type,$uid){
        if(empty($id) || empty($type)){
            throw new BusinessException('Id，类型不能为空！');
        }
        $favoriteData = new FavoriteData();
        return $favoriteData->removeByIdAndType($id,$type,$uid);
    }
    
    public static function updateReadStatusById($id){
        if(empty($id)){
            throw new BusinessException('Id不能为空！');
        }
        $favoriteData = new FavoriteData();
        $favoriteData->updateReadStatusById($id);
    }
    
    /**
     * 关注明星\品牌\博主、设计师
     * @param int $uid ->本人
     * @param int $id->他人
     * @param int $ids
     */
    public static function saveAttention($uid,$id,$type = \haibao\www\model\data\Favorite::ATTENTION_TYPE_STAR){
    	if(empty($id)){
    		throw new BusinessException('Id不能为空！');
    	}
    	$favoriteData = new FavoriteData();
    	$favoriteData->saveAttention($uid, $id,$type);
    	
    	if($type == \haibao\www\model\data\Favorite::ATTENTION_TYPE_USER){
    	    /**
    	     * 谁关注了我，插到表messagebox表
    	     * 
    	     * 我关注了谁，插到userdynamics表
    	     * 
    	     */
    	    
    	    $messageData['FromUserId']=$favoriteData->relationData['FromUserId'];
    	    $messageData['FromNickName']=$favoriteData->relationData['UserName'];
    		$messageData['Content']='关注了我';
    		$messageData['MessageType']=\haibao\www\business\message\MessageBox::MESSAGE_DATA_MESSAGE_TYPE_ATTENTION_USER;
    		\haibao\www\business\message\MessageBox::addUserMessage($favoriteData->relationData['FromUserId'],$favoriteData->relationData['ToUserId'],$messageData);
    		
    		\haibao\user\business\UserDynamics::addUserDynamics(
    		    array(
    		    'UserId'=>$uid,
    		    'InfoId'=>$id,
    		    'InfoType'=>$type,
    		    'MsgType'=>\haibao\user\model\data\UserDynamics::MESSAGE_TYPE_ATTENTION,
    		    ),$favoriteData->relationData);
    	
    	}else{
	    	\haibao\user\business\UserDynamics::addUserDynamics(
	    			array(
	    				'UserId'=>$uid,
	    				'InfoId'=>$id,
	    				'InfoType'=>$type,
	    				'MsgType'=>\haibao\user\model\data\UserDynamics::MESSAGE_TYPE_ATTENTION
	    					
	    	),$favoriteData->relationData);
    	}
    }
    
    public static function getFeatureTitleById($fid){
        $favoriteData = new FavoriteData();
        return $favoriteData->getFeatureTitleById($fid);
    }
    
    public static function getThreadTitleById($id){
        if(empty($id)){
            throw new BusinessException('Id不能为空！');
        }
        $favoriteData = new FavoriteData();
        return $favoriteData->getThreadTitleById($id);
    }
    public static function getBlogTitleById($id){
        if(empty($id)){
            throw new BusinessException('Id不能为空！');
        }
        $favoriteData = new FavoriteData();
        return $favoriteData->getBlogTitleById($id);
    }
    /**
     * 取消关注明星\品牌\博主
     * @param int $uid
     * @param int $id
     * @param int $ids
     */
    public static function clearAttention($uid,$id,$type = \haibao\www\model\data\Favorite::ATTENTION_TYPE_STAR){
    	if(empty($id)){
    		throw new BusinessException('Id不能为空！');
    	}
    	$favoriteData = new FavoriteData();
    	$favoriteData->clearAttention($uid, $id,$type);
    }
    
    /**
     * 是否关注某明星\品牌\博主
     * @param int $uid
     * @param array $ids
     * @param int $ids
     */
    public static function hasAttention($uid,$ids,$type = \haibao\www\model\data\Favorite::ATTENTION_TYPE_STAR){
    	if(empty($ids)){
    		throw new BusinessException('Id不能为空！');
    	}
    	$favoriteData = new FavoriteData();
    	return $favoriteData->hasAttention($uid,$ids,$type);
    }
    
    public static function addVideoUpNum($vid){
        if(empty($vid)){
            throw new BusinessException('视频Id不能为空！');
        }
        $favoriteData = new \haibao\www\data\Video();
        $favoriteData->addVideoUpNum($vid);
    }
    
    public static function getVideoUpNum($vid){
    	if(empty($vid)){
    		throw new BusinessException('视频Id不能为空！');
    	}
    	$favoriteData = new \haibao\www\data\Video();
    	return $favoriteData->getVideoUpNum($vid);
    }
    
    public static function addVideoPlayNum($vid){
        if(empty($vid)){
            throw new BusinessException('视频Id不能为空！');
        }
        $favoriteData = new \haibao\www\data\Video();
        $favoriteData->addVideoPlayNum($vid);
    }
    
    public static function getClickCommentNumByThreadIds($threadIds){
    	$favoriteData = new FavoriteData();
    	return $favoriteData->getClickCommentNumByThreadIds($threadIds);
    }
    public static function getClickCommentNumByBlogIds($blogIds){
    	$favoriteData = new FavoriteData();
    	return $favoriteData->getClickCommentNumByBlogIds($blogIds);
    }
    
    public static function getTotalNumForWap($uid){
    	$favoriteData = new FavoriteData();
    	return $favoriteData->getTotalNumForWap($uid);
    }
    
    public static function getCollectionNum($aidArr,$type){
        $data = new FavoriteData();
        return $data->getCollectionNum($aidArr,$type);
    }
    
    
}
